package leetcode.题库.数组.二分;

/**
 * description:
 *
 * @author 颜真明
 * @date 2024/3/27  14:32
 */
public class Solution209 {
    public static int minSubArrayLen(int target, int[] nums) {
        int lp = 0, sum = 0, minLen = Integer.MAX_VALUE;
        for (int rp = 0; rp < nums.length; rp++) {
            sum += nums[rp];
            while(sum >= target) {
                minLen = Math.min(minLen, rp-lp+1);
                sum -= nums[lp];
                lp++;
            }
        }
        return minLen == Integer.MAX_VALUE ? 0 : minLen;
    }

    public static void main(String[] args) {
        int[] arr = new int[]{1,4,4};
        System.out.println(minSubArrayLen(4,arr));
    }
}
